package com.broad.commerce.code.controller;

import com.broad.commerce.code.models.EntityModuleDTO;
import com.broad.commerce.code.services.AutoCodeService;
import com.broad.commerce.common.constants.MediaTypes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author stephen
 * @version V1.0
 * @date 2022-04-13 16:50
 * @description: ModuleCreateController
 **/
@RestController
@RequestMapping(value = "/module")
public class ModuleCreateController {
	@Autowired
	private AutoCodeService autoCodeService;

	@PostMapping(value = "/jdbc", produces = MediaTypes.APPLICATION_JSON_UTF8)
	public void createJdbcModuleFiles(@RequestBody @Valid EntityModuleDTO entityModuleDTO) {
		this.autoCodeService.createJdbcModuleFiles(entityModuleDTO);
		this.autoCodeService.createBusinessModuleFiles(entityModuleDTO);
	}

	@PostMapping(value = "/batchJdbc", produces = MediaTypes.APPLICATION_JSON_UTF8)
	public void batchCreateJdbcModuleFiles(@RequestBody @Valid List<EntityModuleDTO> entityModuleDTOs) {
		this.autoCodeService.batchCreateJdbcModuleFiles(entityModuleDTOs);
		this.autoCodeService.batchCreateBusinessModuleFiles(entityModuleDTOs);
	}
}
